﻿
using System;
using System.Reflection;
using System.Windows.Forms;

namespace DevelopersToolbox {
    public class Page : IPage {
        private Control _control;
        public string Name { get; private set; }
        public Guid Guid { get; private set; }
        private Type ComponentType { get; set; }

        public Page(Guid guid, string name, Type componentType) {
            Guid = guid;
            Name = name;
            ComponentType = componentType;
        }

        public Control Control {
            get {
                if (_control == null) {
                    _control = CreateComponent();
                }
                return _control;
            }
        }

        protected virtual Control CreateComponent() {
            ConstructorInfo constructor = ComponentType.GetConstructor(new Type[] { });
            Control control = (Control)constructor.Invoke(new object[] { });
            return control;
        }
    }
}
